package com.explorati.design_pattern.behavior.state;

/**
 * 环境(Context)角色：该角色定义客户端需要的接口，并负责具体状态的切换。他会保留一个具体状态类的实例，该实例给出环境对象的现有状态
 * 
 * 这个例子和电视频道不同之处在于，在每一个状态下都有每个状态下的值，比如，暂停时不能切换到停止，而电视频道是可以任意切换的
 * 
 * @author explorati
 *
 */
public class CourseVideoContext {

	// 定义状态
	private CourseVideoState courseVideoState;

	// 当前状态
	public final static PlayState PLAY_STATE = new PlayState();
	public final static StopState STOP_STATE = new StopState();
	public final static SpeedState SPEED_STATE = new SpeedState();
	public final static PauseState PAUSE_STATE = new PauseState();

	// 获取当前状态
	public CourseVideoState getCourseVideoState() {
		return courseVideoState;
	}

	// 设置当前状态
	public void setCourseVideoState(CourseVideoState courseVideoState) {
		this.courseVideoState = courseVideoState;
		// 设置状态中的环境
		this.courseVideoState.setCourseVideoContext(this);
	}

	// 行为委托
	public void play() {
		this.courseVideoState.play();
	}

	public void speed() {
		this.courseVideoState.speed();
	}

	public void pause() {
		this.courseVideoState.pause();
	}

	public void stop() {
		this.courseVideoState.stop();
	}
}
